home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / MultiAnimation / MultiAnimation.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  7.7 KB  |  218 lines

  1. //-----------------------------------------------------------------------------
  2. // File: MultiAnimation.h
  3. //
  4. // Desc: Header file for the MultiAnimation library.  This contains the
  5. //       declarations of
  6. //
  7. //       MultiAnimFrame              (no .cpp file)
  8. //       MultiAnimMC                 (MultiAnimationLib.cpp)
  9. //       CMultiAnimAllocateHierarchy (AllocHierarchy.cpp)
  10. //       CMultiAnim                  (MultiAnimationLib.cpp)
  11. //       CAnimInstance               (AnimationInstance.cpp)
  12. //
  13. // Copyright (c) Microsoft Corporation. All rights reserved
  14. //-----------------------------------------------------------------------------
  15.  
  16.  
  17. #ifndef __MULTIANIMATION_H__
  18. #define __MULTIANIMATION_H__
  19.  
  20.  
  21. #pragma warning( push, 3 )
  22. #pragma warning(disable:4786 4788)
  23. #include <vector>
  24. #pragma warning( pop )
  25. #pragma warning(disable:4786 4788)
  26.  
  27. #include <d3d9.h>
  28. #include <d3dx9.h>
  29.  
  30.  
  31. //#define DEBUG_VS   // Uncomment this line to debug vertex shaders 
  32. //#define DEBUG_PS   // Uncomment this line to debug pixel shaders 
  33.  
  34.  
  35.  
  36.  
  37. //-----------------------------------------------------------------------------
  38. // Forward declarations
  39.  
  40. class CMultiAnim;
  41. class CAnimInstance;
  42.  
  43.  
  44.  
  45.  
  46. //-----------------------------------------------------------------------------
  47. // Name: class CMultiAnimAllocateHierarchy
  48. // Desc: Inheriting from ID3DXAllocateHierarchy, this class handles the
  49. //       allocation and release of the memory used by animation frames and
  50. //       meshes.  Applications derive their own version of this class so
  51. //       that they can customize the behavior of allocation and release.
  52. //-----------------------------------------------------------------------------
  53. class CMultiAnimAllocateHierarchy : public ID3DXAllocateHierarchy
  54. {
  55.     // callback to create a D3DXFRAME-derived object and initialize it
  56.     STDMETHOD( CreateFrame )( THIS_ LPCSTR Name, LPD3DXFRAME *ppNewFrame );
  57.     // callback to create a D3DXMESHCONTAINER-derived object and initialize it
  58.     STDMETHOD( CreateMeshContainer )( THIS_ LPCSTR Name, CONST D3DXMESHDATA * pMeshData, 
  59.                             CONST D3DXMATERIAL * pMaterials, CONST D3DXEFFECTINSTANCE * pEffectInstances,
  60.                             DWORD NumMaterials, CONST DWORD * pAdjacency, LPD3DXSKININFO pSkinInfo, 
  61.                             LPD3DXMESHCONTAINER * ppNewMeshContainer );
  62.     // callback to release a D3DXFRAME-derived object
  63.     STDMETHOD( DestroyFrame )( THIS_ LPD3DXFRAME pFrameToFree );
  64.     // callback to release a D3DXMESHCONTAINER-derived object
  65.     STDMETHOD( DestroyMeshContainer )( THIS_ LPD3DXMESHCONTAINER pMeshContainerToFree );
  66.  
  67. public:
  68.     CMultiAnimAllocateHierarchy();
  69.  
  70.     // Setup method
  71.     STDMETHOD( SetMA )( THIS_ CMultiAnim *pMA );
  72.  
  73. private:
  74.     CMultiAnim *m_pMA;
  75. };
  76.  
  77.  
  78.  
  79.  
  80. //-----------------------------------------------------------------------------
  81. // Name: struct MultiAnimFrame
  82. // Desc: Inherits from D3DXFRAME.  This represents an animation frame, or
  83. //       bone.
  84. //-----------------------------------------------------------------------------
  85. struct MultiAnimFrame : public D3DXFRAME
  86. {
  87. };
  88.  
  89.  
  90.  
  91.  
  92. //-----------------------------------------------------------------------------
  93. // Name: struct MultiAnimMC
  94. // Desc: Inherits from D3DXMESHCONTAINER.  This represents a mesh object
  95. //       that gets its vertices blended and rendered based on the frame
  96. //       information in its hierarchy.
  97. //-----------------------------------------------------------------------------
  98. struct MultiAnimMC : public D3DXMESHCONTAINER
  99. {
  100.     LPDIRECT3DTEXTURE9 *m_apTextures;
  101.     LPD3DXMESH          m_pWorkingMesh;
  102.     D3DXMATRIX *        m_amxBoneOffsets;  // Bone offset matrices retrieved from pSkinInfo
  103.     D3DXMATRIX **       m_apmxBonePointers;  // Provides index to bone matrix lookup
  104.  
  105.     DWORD               m_dwNumPaletteEntries;
  106.     DWORD               m_dwMaxNumFaceInfls;
  107.     DWORD               m_dwNumAttrGroups;
  108.     LPD3DXBUFFER        m_pBufBoneCombos;
  109.  
  110.     HRESULT SetupBonePtrs( D3DXFRAME * pFrameRoot );
  111. };
  112.  
  113.  
  114.  
  115.  
  116. //-----------------------------------------------------------------------------
  117. // Name: class CMultiAnim
  118. // Desc: This class encapsulates a mesh hierarchy (typically loaded from an
  119. //       .X file).  It has a list of CAnimInstance objects that all share
  120. //       the mesh hierarchy here, as well as using a copy of our animation
  121. //       controller.  CMultiAnim loads and keeps an effect object that it
  122. //       renders the meshes with.
  123. //-----------------------------------------------------------------------------
  124. class CMultiAnim
  125. {
  126.     friend class CMultiAnimAllocateHierarchy;
  127.     friend class CAnimInstance;
  128.     friend struct MultiAnimFrame;
  129.     friend struct MultiAnimMC;
  130.  
  131. protected:
  132.  
  133.     LPDIRECT3DDEVICE9         m_pDevice;
  134.  
  135.     LPD3DXEFFECT              m_pEffect;
  136.     char *                    m_sTechnique;           // character rendering technique
  137.     DWORD                     m_dwWorkingPaletteSize;
  138.     D3DXMATRIX *              m_amxWorkingPalette;
  139.  
  140.     std::vector< CAnimInstance* >  m_v_pAnimInstances;     // must be at lesat 1; otherwise, clear all
  141.  
  142.     MultiAnimFrame *          m_pFrameRoot;           // shared between all instances
  143.     LPD3DXANIMATIONCONTROLLER m_pAC;                  // AC that all children clone from -- to clone clean, no keys
  144.  
  145.     // useful data an app can retrieve
  146.     float                     m_fBoundingRadius;
  147.  
  148. private:
  149.  
  150.             HRESULT           CreateInstance( CAnimInstance ** ppAnimInstance );
  151.             HRESULT           SetupBonePtrs( MultiAnimFrame * pFrame );
  152.  
  153. public:
  154.  
  155.                               CMultiAnim();
  156.     virtual                   ~CMultiAnim();
  157.  
  158.     virtual HRESULT           Setup( LPDIRECT3DDEVICE9 pDevice, TCHAR sXFile[], TCHAR sFxFile[], CMultiAnimAllocateHierarchy *pAH, LPD3DXLOADUSERDATA pLUD = NULL );
  159.     virtual HRESULT           Cleanup( CMultiAnimAllocateHierarchy * pAH );
  160.  
  161.             LPDIRECT3DDEVICE9 GetDevice();
  162.             LPD3DXEFFECT      GetEffect();
  163.             DWORD             GetNumInstances();
  164.             CAnimInstance *   GetInstance( DWORD dwIdx );
  165.             float             GetBoundingRadius();
  166.  
  167.     virtual HRESULT           CreateNewInstance( DWORD * pdwNewIdx );
  168.  
  169.     virtual void              SetTechnique( char * sTechnique );
  170.  
  171.     virtual HRESULT           Draw();
  172. };
  173.  
  174.  
  175.  
  176.  
  177. //-----------------------------------------------------------------------------
  178. // Name: class CAnimInstance
  179. // Desc: Encapsulates an animation instance, with its own animation controller.
  180. //-----------------------------------------------------------------------------
  181. class CAnimInstance
  182. {
  183.     friend class CMultiAnim;
  184.  
  185. protected:
  186.  
  187.     CMultiAnim                *m_pMultiAnim;
  188.     D3DXMATRIX                 m_mxWorld;
  189.     LPD3DXANIMATIONCONTROLLER  m_pAC;
  190.  
  191. private:
  192.  
  193.     virtual HRESULT     Setup( LPD3DXANIMATIONCONTROLLER pAC );
  194.     virtual void        UpdateFrames( MultiAnimFrame * pFrame, D3DXMATRIX * pmxBase );
  195.     virtual void        DrawFrames( MultiAnimFrame * pFrame );
  196.     virtual void        DrawMeshFrame( MultiAnimFrame * pFrame );
  197.  
  198. public:
  199.  
  200.                         CAnimInstance( CMultiAnim * pMultiAnim );
  201.     virtual             ~CAnimInstance();
  202.  
  203.     virtual void        Cleanup();
  204.  
  205.             CMultiAnim* GetMultiAnim();
  206.             void        GetAnimController( LPD3DXANIMATIONCONTROLLER * ppAC );
  207.  
  208.             D3DXMATRIX  GetWorldTransform();
  209.             void        SetWorldTransform( const D3DXMATRIX * pmxWorld );
  210.  
  211.     virtual HRESULT     AdvanceTime( DOUBLE dTimeDelta, ID3DXAnimationCallbackHandler * pCH );
  212.     virtual HRESULT     ResetTime();
  213.     virtual HRESULT     Draw();
  214. };
  215.  
  216.  
  217. #endif // #ifndef __MULTIANIMATION_H__
  218.